<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
if($_RQ['op']=='main'){
		$return['pluginset']=$basic=$set= $this->plugin_setting('setting');
		$id = intval($_RQ['id']);
		$return['sharedata']=array(
			'title'=>$basic['share_title']?$basic['share_title']:'全网论坛',
			'desc'=>$basic['share_desc'],
			'link'=>custom_url('jy_sns/user.index/id='.$id,true),
			'imgUrl'=>ATTACHMENT_URL.$basic['share_icon'],
		);
		if (empty($id)) 
		{
			$member = getMember($_SESSION['uid']);
			$id=$_SESSION['uid'];
		}
		else 
		{
			$member =getMember($id);
		}
		
		
		if (empty($member)) 
		{
			exi('未找到用户!', 'error', '/index/');
		}
		$mid = $id;
		$mymid=	$_SESSION['uid'];
		$level = array('levelname' => (empty($set['levelname']) ? '社区粉丝' : $set['levelname']), 'color' => (empty($set['levelcolor']) ? '#333' : $set['levelcolor']), 'bg' => (empty($set['levelbg']) ? '#eee' : $set['levelbg']));
		if (!(empty($member['sns_level']))) 
		{
			$level = pdo_get('jy_sns_level',array('id'=>$member['sns_level']));
		}
		$boardcount = pdo_count('jy_sns_board_follow',array('uniacid' => $_SESSION['uniacid'], 'mid' => $mid));
		$postcount = pdo_count('jy_sns_post',array('uniacid' => $_SESSION['uniacid'], 'mid' => $mid,'deleted'=>0));
		$postcount =$postcount?$postcount:0 ;
		$boards = pdo_fetchall('select b.id,b.logo,b.title from ' . tablename('jy_sns_board') . ' b ' . ' left join ' . tablename('jy_sns_board_follow') . ' f on f.bid = b.id ' . '   where f.uniacid='.$_SESSION['uniacid'].' and f.mid='.$id);
		$followcount = pdo_count('jy_sns_board_follow',array('mid'=>$id));
		//$posts = pdo_fetchall('select p.id,p.images,p.title ,p.views, b.title as boardtitle,b.logo as boardlogo from ' . tablename('jy_sns_post') . ' p ' . ' left join ' . tablename('jy_sns_board') . ' b on p.bid = b.id ' . '   where p.uniacid='.$_SESSION['uniacid'],' and p.mid='.$mid.' and pid=0 and deleted=0 and checked=1 order by createtime desc limit 3');
		$posts = pdo_getall('jy_sns_post',array('uniacid' => $_SESSION['uniacid'],'mid'=>$id,'deleted'=>0));
		
		foreach ($posts as &$r ) 
		{
			
			$r['images'] = tomedia($r['images']);
			$r['logo'] = tomedia($r['logo']);
			$b=pdo_get('jy_sns_board',array('id'=>$r['bid']),array('title','logo'));
			$r['boardtitle'] =$b['title'];
			$r['boardlogo'] = $b['logo'];
		}
		unset($r);
		if ($mid == $_SESSION['uid']) 
		{
			//$replycount = pdo_count('jy_sns_post',array('mid'=>$mid,'pid'>0,'checked'=>1,'deleted'=>0,'uniacid'=>$_SESSION['uniacid']));
			$replys = pdo_fetchall('select p.id, p.content, p.views,' . "\n" . '                  parent.id as parentid, ' . "\n" . '                  parent.nickname as parentnickname,parent.title as parenttitle ,' . "\n" . '                  rparent.nickname as rparentnickname' . "\n" . '                  from ' . tablename('jy_sns_post') . ' p ' . ' left join ' . tablename('jy_sns_post') . ' parent on p.pid = parent.id ' . ' left join ' . tablename('jy_sns_post') . ' rparent on p.rpid = rparent.id ' . '   where p.uniacid='.$_SESSION['uniacid'],' and p.mid='.$mid.' and p.pid>0 and p.deleted=0 and p.checked=1 order by p.createtime desc limit 3');
			foreach ($replys as &$r ) 
			{
				$parentnickname = $r['rparentnickname'];
				if (empty($parentnickname)) 
				{
					$parentnickname = $r['parentnickname'];
				}
				$r['parentnickname'] = $parentnickname;
			}
			unset($r);
		}
	
		$return['member']=$member;
		$return['mid']=$mid;
		$return['mymid']=$mymid;
		$return['level']=$level;
		$return['boardcount']=$boardcount;
		$return['postscount']=$postcount;
		$return['boards']=$boards;
		$return['followcount']=$followcount?$followcount:0;
		$return['posts']=$posts;
		$return['replycount']=$replycount;
		$return['replys']=$replys;
		$return['params']=array('mid'=>$mid);
		exi($return);
	}
?>